use iced::Font;

/// Font constants for the application
pub struct Fonts;

impl Fonts {
    /// Default font for the application - using system default with fallback
    pub const DEFAULT: Font = Font::DEFAULT;

    /// Monospace font for code/SQL editor
    pub const MONOSPACE: Font = Font::MONOSPACE;

    /// Alternative fonts for different systems
    pub const FALLBACK_CHINESE: &'static [&'static str] = &[
        "Microsoft YaHei",      // Windows
        "SimSun",               // Windows fallback
        "SimHei",               // Windows fallback
        "PingFang SC",          // macOS
        "Noto Sans CJK SC",     // Linux
        "Arial Unicode MS",     // Universal fallback
        "sans-serif",           // System fallback
    ];

    pub const FALLBACK_MONOSPACE: &'static [&'static str] = &[
        "Consolas",             // Windows
        "Courier New",          // Windows fallback
        "Monaco",               // macOS
        "Menlo",                // macOS
        "DejaVu Sans Mono",     // Linux
        "Liberation Mono",      // Linux
        "monospace",            // System fallback
    ];

    /// Get the best available font for Chinese text
    pub fn get_chinese_font() -> Font {
        // Use a font that's guaranteed to be available on Windows
        // and supports Chinese characters well
        #[cfg(target_os = "windows")]
        {
            Font::with_name("SimSun")
        }
        #[cfg(target_os = "macos")]
        {
            Font::with_name("PingFang SC")
        }
        #[cfg(target_os = "linux")]
        {
            Font::with_name("Noto Sans CJK SC")
        }
        #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
        {
            Font::DEFAULT
        }
    }

    /// Get the best available monospace font
    pub fn get_monospace_font() -> Font {
        // Use system default monospace font
        Font::MONOSPACE
    }

    /// Get font for UI elements
    pub fn get_ui_font() -> Font {
        Self::get_chinese_font()
    }
}

/// Font sizes used throughout the application
pub mod sizes {
    /// Extra small text (10px)
    pub const XS: u16 = 10;
    
    /// Small text (12px)
    pub const SM: u16 = 12;
    
    /// Medium text (14px) - default
    pub const MD: u16 = 14;
    
    /// Large text (16px)
    pub const LG: u16 = 16;
    
    /// Extra large text (18px)
    pub const XL: u16 = 18;
    
    /// 2X large text (20px)
    pub const XL2: u16 = 20;
    
    /// 3X large text (24px)
    pub const XL3: u16 = 24;
}

/// Font weights
pub mod weights {
    /// Normal weight (400)
    pub const NORMAL: u16 = 400;
    
    /// Medium weight (500)
    pub const MEDIUM: u16 = 500;
    
    /// Semi-bold weight (600)
    pub const SEMIBOLD: u16 = 600;
    
    /// Bold weight (700)
    pub const BOLD: u16 = 700;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_font_constants() {
        // Test that font constants are properly defined
        // Note: DEFAULT and MONOSPACE are system defaults, not specific fonts
        assert!(matches!(Fonts::DEFAULT.family, iced::font::Family::SansSerif));
        assert!(matches!(Fonts::MONOSPACE.family, iced::font::Family::Monospace));
    }

    #[test]
    fn test_font_sizes() {
        assert_eq!(sizes::XS, 10);
        assert_eq!(sizes::SM, 12);
        assert_eq!(sizes::MD, 14);
        assert_eq!(sizes::LG, 16);
    }

    #[test]
    fn test_fallback_fonts() {
        assert!(!Fonts::FALLBACK_CHINESE.is_empty());
        assert!(!Fonts::FALLBACK_MONOSPACE.is_empty());
        assert!(Fonts::FALLBACK_CHINESE.contains(&"Microsoft YaHei"));
        assert!(Fonts::FALLBACK_MONOSPACE.contains(&"Consolas"));
    }
}
